﻿#ifndef SERVOCONTROL_H
#define SERVOCONTROL_H

#include <QWidget>
#include <QTimer>
#include <QMap>
#include "./Manager/DispatchCore.h"
#include "Base/Command.h"
#include <QImage>
namespace Ui {
class ServoControl;
}

class ServoControl : public QWidget
{
    Q_OBJECT

public:
    explicit ServoControl(QWidget *parent = nullptr);
    ~ServoControl();
    void showEvent(QShowEvent *e);

    const static int8_t Location_Origin = 0;    //原点
    const static int8_t Location_Origining = 1; //回原点中
    const static int8_t Location_FaceA = 2;     //A面，取货口面
    const static int8_t Location_FaceAing = 3;
    const static int8_t Location_FaceB = 4;    //B面，取货口对面
    const static int8_t Location_FaceBing = 5;
    const static int8_t Location_Moving = 6;  //非特定位置移动中
    const static int8_t Location_NoneOrigin = 7; //非原点位置
    const static int8_t Location_Porting = 8;   //XY出货口目标位置移动中
    const static int8_t Location_Port = 9;      //XY到达出货口目标位置
    const static int8_t Location_Clamping = 10; //抓取中
    const static int8_t Location_Clamped = 11;  //抓取完成
    const static int8_t Location_Loosening = 12;
    const static int8_t Location_Loosened = 13;

    inline bool stringToint(QString str,int &value,int base);
    void delay_msec(unsigned int msec);
    InOutCabCommand_Board packInOutCabCmd();
signals:
    void sig_setParams(int deviceno,int objectindex,int value);
    void sig_setProbe(quint8 deviceno,quint8 type);
    void sig_setControl(uint8_t deviceno,uint8_t value);
    void sig_moveCmd(QString,int,int,QString);
    void sig_imgCmd();
    void sig_inOutCabCmd(InOutCabCommand_Board);

    void sig_addLog(QString,QString);
private slots:
    void slot_imgCmdResult(QImage);
    void on_ip_rwcontrolword_returnPressed();

    void on_ip_rwtargetpositon_returnPressed();

    void on_ip_rwtrapespeed_returnPressed();

    void on_ip_rwtrapeacc_returnPressed();

    void on_ip_rwtrapedcc_returnPressed();

    void on_ip_rwtargetspeed_returnPressed();

    void on_ip_rwtargetniuju_returnPressed();

    void on_ip_rwcanheart_returnPressed();

    void on_ip_rwencoder_returnPressed();

    void on_cb_rwcanrate_currentTextChanged(const QString &arg1);

    void slot_setParamsResult(QJsonObject);

    void slot_ParamsResult(QJsonObject);

    void on_bt_poweroff1_clicked();

    void on_bt_poweion1_clicked();

    void on_bt_quickstop1_clicked();

    void on_bt_absolute1_clicked();

    void on_bt_relative1_clicked();

    void on_bt_follow1_clicked();

    void on_bt_oringin1_clicked();

    void on_bt_clearfault1_clicked();

    void on_cb_rwwokemode_currentIndexChanged(int index);

    void on_bt_save1_clicked();

    void on_bt_reboot1_clicked();

    void on_cb_rwwokemode_2_currentIndexChanged(int index);

    void on_ip_rwcontrolword_2_returnPressed();

    void on_ip_rwtargetpositon_2_returnPressed();

    void on_ip_rwtrapespeed_2_returnPressed();

    void on_ip_rwtrapeacc_2_returnPressed();

    void on_ip_rwtrapedcc_2_returnPressed();

    void on_ip_rwtargetspeed_2_returnPressed();

    void on_ip_rwtargetniuju_2_returnPressed();

    void on_cb_rwcanrate_2_currentTextChanged(const QString &arg1);

    void on_ip_rwcanheart_2_returnPressed();

    void on_ip_rwencoder_2_returnPressed();

    void on_bt_poweroff_2_clicked();

    void on_bt_poweion_2_clicked();

    void on_bt_quickstop_2_clicked();

    void on_bt_absolute_2_clicked();

    void on_bt_relative_2_clicked();

    void on_bt_follow_2_clicked();

    void on_bt_oringin_2_clicked();

    void on_bt_clearfault_2_clicked();

    void on_bt_save_2_clicked();

    void on_bt_reboot_2_clicked();

    void on_ip_break_returnPressed();

    void on_bt_flush_clicked();

    void on_bt_flush_2_clicked();

    void on_cb_rwwokemode_3_currentIndexChanged(int index);

    void on_ip_rwcontrolword_3_returnPressed();

    void on_ip_rwtargetpositon_3_returnPressed();

    void on_ip_rwtrapespeed_3_returnPressed();

    void on_ip_rwtrapeacc_3_returnPressed();

    void on_ip_rwtrapedcc_3_returnPressed();

    void on_ip_rwtargetspeed_3_returnPressed();

    void on_ip_rwtargetniuju_3_returnPressed();

    void on_cb_rwcanrate_3_currentTextChanged(const QString &arg1);

    void on_ip_rwcanheart_3_returnPressed();

    void on_ip_rwencoder_3_returnPressed();

    void on_bt_poweroff_3_clicked();

    void on_bt_poweion_3_clicked();

    void on_bt_quickstop_3_clicked();

    void on_bt_absolute_3_clicked();

    void on_bt_relative_3_clicked();

    void on_bt_follow_3_clicked();

    void on_bt_oringin_3_clicked();

    void on_bt_clearfault_3_clicked();

    void on_bt_save_3_clicked();

    void on_bt_reboot_3_clicked();

    void on_bt_flush_3_clicked();

    void on_cb_rwwokemode_4_currentIndexChanged(int index);

    void on_ip_rwcontrolword_4_returnPressed();

    void on_ip_rwtargetpositon_4_returnPressed();

    void on_ip_rwtrapespeed_4_returnPressed();

    void on_ip_rwtrapeacc_4_returnPressed();

    void on_ip_rwtargetspeed_4_returnPressed();

    void on_cb_rwcanrate_4_currentTextChanged(const QString &arg1);

    void on_ip_rwcanheart_4_returnPressed();

    void on_ip_rwtrapedcc_4_returnPressed();

    void on_bt_poweroff_4_clicked();

    void on_bt_poweion_4_clicked();

    void on_bt_quickstop_4_clicked();

    void on_bt_absolute_4_clicked();

    void on_bt_relative_4_clicked();

    void on_bt_follow_4_clicked();

    void on_bt_oringin_4_clicked();

    void on_bt_clearfault_4_clicked();

    void on_bt_save_4_clicked();

    void on_bt_reboot_4_clicked();

    void on_bt_flush_4_clicked();

    void on_ip_rworinginmode_returnPressed();

    void on_ip_rworinginmode_2_returnPressed();

    void on_ip_rworinginmode_3_returnPressed();

    void on_ip_rworinginmode_4_returnPressed();

    void on_btn_movez_clicked();

    void on_btn_movexy_clicked();

    void on_btn_rotate_clicked();

    void on_btn_clmap_clicked();

    void on_btn_loosen_clicked();

    void on_btn_rotateorigin_clicked();

    void on_btn_rotateA_clicked();

    void on_btn_rotateB_clicked();

    void on_btn_zrotateA_clicked();

    void on_btn_zrotateB_clicked();

    void on_ck_storge_stateChanged(int arg1);

    void on_ck_fetch_stateChanged(int arg1);

    void on_btn_inoutcabcmd_clicked();

    void on_btn_inoutcabnext_clicked();

    void on_btn_rise_clicked();

    void on_btn_fall_clicked();

    void on_btn_stop_clicked();

    void on_btn_zarb_clicked();

    void on_btn_zbra_clicked();

    void on_btn_nostop_clicked();

    void on_btn_image_clicked();

private:
    Ui::ServoControl *ui;
    QTimer* t;
    QMap<int,int> workModeMap;
    QStringList workModeList;
    QMap<int,int> workModeMap_Step;
    QStringList workModeList_Step;
    uint8_t servoCanNo[4] = {1,2,3,4}; //电机Can站号
    InOutCabCommand_Board lastCmd;
};

#endif // SERVOCONTROL_H
